package com.wframe.project.jnd.tag.web;

import java.util.List;
import java.util.Map;

import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.frame.database.JdataBean;
import com.frame.database.PageResult;
import com.wframe.framework.spring.SpringContextHolder;
import com.wframe.project.jnd.services.InformationService;

public class InfoTag extends RequestContextAwareTag{
	
	private static final long serialVersionUID = 1L;
	private String code;
	private Integer psize;
	private Integer pno;
	private int indexId=0;
	InformationService informationService;
	private List<Map> list;
	
	@Override
	protected int doStartTagInternal() throws Exception {
		indexId=0;
		informationService=SpringContextHolder.getBean(InformationService.class);
		JdataBean parms=new JdataBean();
		int size=10;if(psize!=null)size=psize.intValue();
		int no=1;if(pno!=null)no=pno.intValue();
		parms.put("code", code);
		PageResult pr=informationService.queryInfos(parms, size, no);
		list=pr.getList();
		if(next()){
			return EVAL_BODY_INCLUDE;
		}else return 0;
	}

	public int doAfterBody(){
		if(next()){
			return EVAL_BODY_AGAIN;
		}else return 0;
	}
	
	public int doEndTag(){
		list=null;
		if(pno!=null){
		
		}
		return 0;
	}
	
	private boolean next(){
		if(list!=null && indexId<list.size()){
			Map bean=list.get(indexId);
			Object[] keys=bean.keySet().toArray();
			for(Object key:keys)
				pageContext.getRequest().setAttribute(key.toString(),bean.get(key.toString()));
			indexId++;
			return true;
		}else return false;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getPsize() {
		return psize;
	}

	public void setPsize(Integer psize) {
		this.psize = psize;
	}

	public Integer getPno() {
		return pno;
	}

	public void setPno(Integer pno) {
		this.pno = pno;
	}
	
}
